package cn.t.facade.user;

import cn.t.converter.user.CustomerIndividualDTOConverter;
import cn.t.core.facade.FacadeImpl;
import cn.t.dto.user.CustomerIndividualDTO;
import cn.t.model.user.CustomerIndividualDO;
import cn.t.service.user.CustomerIndividualService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 单位信息表服务编排
 */
@Slf4j
@Service
@AllArgsConstructor
public class CustomerIndividualFacade extends FacadeImpl<CustomerIndividualDTO, CustomerIndividualDO, CustomerIndividualDTOConverter, CustomerIndividualService> {


    public void updateCustomer(CustomerIndividualDTO customerIndividual) {

        if (customerIndividual == null || customerIndividual.getId() == null || customerIndividual.getId() < 1L || StringUtils.isBlank(customerIndividual.getCustomerName())) {
            return;
        }

        CustomerIndividualDO template = new CustomerIndividualDO();
        template.setId(customerIndividual.getId());
        template.setCustomerName(customerIndividual.getCustomerName());
        template.setGmtModified(new Date());

        service.update(template);
    }

    public void deleteCustomer(Long individualId) {
        CustomerIndividualDO individualDO = service.findById(individualId);
        if (individualDO == null || !individualDO.getId().equals(individualId)) {
            return;
        }
        service.deleteCustomer(individualId);
    }
}

